package com.lightsaber.trade.core.common.treegrid;

import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class GridDoc {

    @SuppressWarnings("unchecked")
    public static Iterator<Element> parseChanges(String xml) throws DocumentException {
        if (xml.charAt(0) == '&') {
            xml = xml.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&")
                    .replaceAll("&quot;", "\"").replaceAll("&apos;", "'");
        }

        Document changeDoc = DocumentHelper.parseText(xml);
        Element grid = changeDoc.getRootElement();
        Element changes = grid.element("Changes");
        return changes.elementIterator("I");
    }

    public static void main(final String[] args) {
        new GridDoc();
    }

}
